#include "ipc.h"
#include "proc.h"
#include "page.h"

#include "kparam.h"


#define SEND_MSG	0
#define RECV_MSG	1

int msg_check(struct message *msg){
	return 0;
}

int remap_msg(struct proc *proc_p,uint_32 msg_type,uint_32 msg_p,uint_32 *kmsg_p){
#if 0
	uint_32 phy;
	vm2phy(&(proc_p->mm),&msg_p,&phy);
	phy = round_backward(phy,PG_SIZE);	/* find the page start address */
	if (msg_type == SEND_MSG){
		kremap(KMAP_MSG_SRC,phy);
		*kmsg_p = KMAP_MSG_SRC_VM | (msg_p & 0x00000FFF);
	}else{
		kremap(KMAP_MSG_DST,phy);
		*kmsg_p = KMAP_MSG_DST_VM | (msg_p & 0x00000FFF);
	}
#endif
	return 0;
}


int send(struct message *msg){
	uint_32 send_msg_p;
	uint_32 recv_msg_p;
	
	cur_proc->status = SUSPEND;
	cur_proc->ipc_with= &(proc[msg->dst]);

	remap_msg(cur_proc,SEND_MSG,(uint_32)msg,&send_msg_p);
	remap_msg(&(proc[msg->dst]),RECV_MSG,(uint_32)proc[msg->dst].msg,&recv_msg_p);
	vmcopy(recv_msg_p, send_msg_p, MSG_LEN);

	return 0;
}

int recv(struct message *msg){
	return 0;
}

int notify(struct message *msg){
	return 0;
}

